package com.wzy.designpattern.structural.proxy.staticproxy;

import com.wzy.designpattern.structural.proxy.IOrderService;
import com.wzy.designpattern.structural.proxy.Order;
import com.wzy.designpattern.structural.proxy.OrderServiceImpl;

/**
 * 描述
 * 创建人    Wzy
 * 创建时间: 2020-05-16  14:38
 */
public class OrderServiceStaticProxy {
    private IOrderService iOrderService;

    public int saveOrder(Order order) {
        beforeMethod();
        iOrderService = new OrderServiceImpl();
        int userId = order.getUserId();
        int dbRouter = userId % 2;
        System.out.println("静态代理分配到[ db" + dbRouter + " ] 处理数据");
        afterMethod();
        return 1;
    }

    private void beforeMethod() {
        System.out.println("静态代理 before code");
    }

    private void afterMethod() {
        System.out.println("静态代理 after code");
    }
}
